/*
    The I Ching (the Book of Changes) plasmoid.
    Copyright (C) 2002-2009 Jean Pierre Charalambos.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef TRIGRAM_H
#define TRIGRAM_H

#include <QVector>
#include "line.h"

/**
  *@author Jean Pierre Charalambos
  */

/*! \brief An I Ching trigram
\class Trigram trigram.h trigram.h

A trigram is an entity that represents a quality of elemental energy.

A trigram consists of three lines. There are two different systems that represent the set of all the trigrams:
the Before Heaven system, attributed to Fu Hsi and the After Heaven system, attributed to King Wen. Of the two,
the latter is almost the only one referred in today's I Ching literature.

Thus this class follows the "After Heaven" convention which is the most widely spread.

\nosubgrouping */

class Trigram : public Datagram {
        Q_OBJECT
        friend class Hexagram;
    public:
        Trigram();
        Trigram ( int );
        Trigram ( Line *, Line *, Line * );
        Trigram ( QVector<int> );
        Trigram ( int, int, int );
        virtual ~Trigram() {
            components.clear();
        }
        const Line * getComponent ( int i ) const {
            return components.at ( i%3 );
        }
        const QString & getImage() const {
            return image;
        }
        const QString & getFamily() const {
            return family;
        }
        const QVector<int> getIdVector() const {
            QVector<int> vec;
            for ( int i=0; i <3; i++ )
                vec.append ( components.at ( i )->getId() );
            return vec;
        }

    public slots:
        void setLine ( int i, Line *l ) {
            components[ i%3 ] = l;
            setId();
        }
        void setLine ( int i, int j ) {
            components.at ( i%3 )->setId ( j );
        }
        void setLineRandomly ( int i ) {
            components.at ( i%3 )->setId();
        }
        void setChangingLine ( int pos ) {
            if ( components.at ( pos%3 )->getId() == 1 )
                components[ pos%3 ]->setId ( 3 );
            if ( components.at ( pos%3 )->getId() == 2 )
                components[ pos%3 ]->setId ( 0 );
        }
        void setFixedLine ( int pos ) {
            if ( components.at ( pos%3 )->getId() == 3 )
                components[ pos%3 ]->setId ( 1 );
            if ( components.at ( pos%3 )->getId() == 0 )
                components[ pos%3 ]->setId ( 2 );
        }

    protected slots:
        //adjust trigram id from components:
        virtual void generate();
        //adjust components from trigram id:
        virtual void adjust ( int );
        virtual void setName();

    protected:
        QVector<Line *> components;
        QString eng_name;
        QString image;
        QString family;
};

#endif  // TRIGRAM_H
